<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>promise api</title>
</head>

<body>

    <script>
        const foo = function() {
            return new Promise(function(resolve, reject) {
                //通过setTimeout模拟一个异步任务
                setTimeout(function() {
                    //正常情况
                    resolve('success');
                    //模拟失败的状态
                    //reject('error');
                }, 500);
            });
        }
        foo().then(function(data) {
            console.log("resolve状态", data);
        }).catch(function(data) {
            console.log("reject状态", data);
        }).finally(function() {
            console.log("finally....");
        });
    </script>
</body>

</html>